package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.Student;
import com.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("page")
    public String page(Page page, Model model, String name, String age){
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        if (name==null){
           name="";
        }
        if (age==null){
            age="";
        }
       // Student student = new Student();

        queryWrapper.like(Student::getName,name);
        queryWrapper.gt(Student::getAge,age);
        Page<Student> page1=new Page<>(page.getCurrent(),3);
        Page<Student> pageInfo=studentService.findAll(page1,queryWrapper);
        model.addAttribute("students",pageInfo);
        return "list";


    }


    @RequestMapping("del")
    public String delete(String id){
        studentService.del(id);
        return "redirect:/page";
    }

}
